import nb_log

from fastapi import APIRouter
from pydantic import BaseModel
from funcs import alert_wechat
from utils.response_utils import response_403
class TaskStatusModel(BaseModel):
    task_id: str


logger = nb_log.get_logger("platform")

router = APIRouter(
    prefix="/alert"
)


@router.get("/wechat/",description="微信告警")
def alert_wechat_api(wx_name=None,room_name=None, message: str = "这是一个测试告警"):
    """
    接口直接最大阻塞120s直到任务执行完成
    wx_name:微信昵称，注意不要有特殊符号
    room_name:微信群名，注意不要有特殊符号

    """
    if wx_name and room_name:
        return response_403(message="微信昵称(wx_name)和群组(room_name)不能同时存在")
    async_result = alert_wechat.push(wx_name,room_name, message)
    logger.debug(f"返回taskid给前端： [{async_result.task_id}]")
    model = TaskStatusModel(task_id=async_result.task_id)
    return model
